using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using AmazonCommon.Amazon.ECS;
using System.Text;

namespace AmazonVer3.Controllers
{
    public class ReviewController : ApplicationController
    {
        //
        // GET: /Review/

        public ActionResult List(string id)
        {
            //the id is the ASIN
            string[] idAndTitle = id.Split(new char[] { '-' });

            Item product = AmazonHelper.GetProductDetail(idAndTitle[0]);

            ViewData[VDConstants.PageTitle] = GenerateTitleFromProductDetails(product);

            return View("CustomerReviews", product);
            return View();
        }

        public ActionResult Show(string id)
        {
            //the id is the ASIN
            string[] idPageReviewNumber = id.Split(new char[] { '-' });
            string asin = idPageReviewNumber[0];
            string page = idPageReviewNumber[1];
            int reviewNumber = int.Parse(idPageReviewNumber[2]);

            Item product = AmazonHelper.GetProductDetailFromAmazonWithReviews(asin, page, ""); ;
            //if (product.CustomerReviews.Review == null)
            //{
            //    Response.StatusCode = 301;
            //    Response.Redirect("~/",true);
            //}
            //ViewData[VDConstants.PageTitle] = GenerateTitleFromProductDetailsForSingleReview(product, product.CustomerReviews.Review[reviewNumber]);
            //ViewData[VDConstants.ReviewToShow] = product.CustomerReviews.Review[reviewNumber];
            return View("SingleReview", product);
        }

        //private object GenerateTitleFromProductDetailsForSingleReview(Item product, Review review)
        //{

        //    StringBuilder result = new StringBuilder();
        //    result.Append(review.Summary);
        //    result.Append(" - ");
        //    result.Append("Review For ");
        //    result.Append(product.ItemAttributes.Title);

        //    return result.ToString();
        //}

        private object GenerateTitleFromProductDetailsForSingleReview(Item product)
        {
            throw new NotImplementedException();
        }

        private string GenerateTitleFromProductDetails(Item product)
        {
            StringBuilder result = new StringBuilder();
            result.Append("Customer Reviews For " + product.ItemAttributes.Title);
            return result.ToString();
        }

        public ActionResult View(string id)
        {
            //
            return View();
        }


    }
}
